package com.itheima.deom;


import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;

public class demo {
                   private SqlSession session;
                   private UserMapper mapper ;
    /*前置注解*/
        @Before
    public void before()throws Exception{
            //1. 读取核心配置文件
            InputStream is = Resources.getResourceAsStream ( "spring.xml" );
               // 2 .构建SqlsessionFactory
            SqlSessionFactory factory = new SqlSessionFactoryBuilder ().build ( is );
              // 3 .获取Sqlsession
            session = factory.openSession ();
              // 4 .通过SqlSession获取Mapper接口的代理对象
            mapper = session.getMapper ( UserMapper.class );
        }
        @After
      public void after(){
            //6.事务提交
              session.commit ();
              // 7 .关闭session
            session.close ();
        }
          @Test
    public void test(){
              List <User> list = mapper.findAll ();
              System.out.println (list);
          }
}
